package com.firebird.app.kotlin.stock.utils

import android.os.CountDownTimer
import android.text.SpannableString
import android.widget.TextView


/**
 * Created by Administrator on 2016/12/4 0004.
 */
class CountDownTimerUtils
/**
 * 60s后获取验证码
 */(private val mTextView: TextView, millisInFuture: Long, countDownInterval: Long) : CountDownTimer(millisInFuture, countDownInterval) {
    override fun onTick(millisUntilFinished: Long) {
        mTextView.isClickable = false //设置不可点击
        mTextView.setText(millisUntilFinished / 1000.toString() + "  s") //设置倒计时时间
        //        mTextView.setTextColor(Color.parseColor("#117AE7"));
//mTextView.setBackgroundResource(R.drawable.vercode); //设置按钮为灰色，这时是不能点击的
        val spannableString = SpannableString(mTextView.text.toString())
        // ForegroundColorSpan span = new ForegroundColorSpan(Color.WHITE);
//spannableString.setSpan(span, 0, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);//将倒计时的时间设置为红色
        mTextView.text = spannableString
    }

    override fun onFinish() {
        mTextView.text = "获取验证码"
        //        mTextView.setTextColor(Color.parseColor("#117AE7"));
        mTextView.isClickable = true //重新获得点击
        //mTextView.setBackgroundResource(R.drawable.vercode);  //还原背景色
    }

}